<?php
namespace app\admin\controller;
use app\admin\Controller;
use app\admin\model\AdminLog as AdminLogModel;
use pidan\facade\Request;
use pidan\facade\Db;
use pidan\facade\Validate;




class AdminLog extends Controller
{
	public function list(){
	    $req=$this->request;
        $table=new AdminLogModel;

        //要显示的
        $filed=explode(',','id, username, title,  ip, createtime');

        //去除空 查询没填写项
        $where1=$req->only(['username','ip'],'get','trim');
        foreach($where1 as $k=>$v){
            if(empty($v)) unset($where1[$k]);
        }
        $title=input('request.title','','trim');
        $where2=empty($title) ? [] :[['title','like','%'.mysql_like_quote($title).'%']];

        $page=input('request.page',1,'intval');
        $limit=input('request.limit',30,'intval');

        $list= $table->field($filed)->where($where1)->where($where2);

        $count=$list->count('id');
        $list=$list->page($page)->limit($limit)->select()->toArray();
		return $this->lists($list,$count);//return $this->result(['code'=>0,'msg'=>'','count'=>$count,'data'=>$list]);
	}
    	public function del(){
	        $ids=input('request.ids',[],'intval');
            AdminLogModel::whereIn('id',$ids)->delete();
    		$this->adminLog('删除管理日志:'.'id-'.implode(',',$ids));
    		$result=['code'=>0,'msg'=>''];
    		return $this->result($result);
    	}
}
